package com.tygz.service.impl;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.base.common.CommonConstants;
import com.bcloud.msg.http.HttpSender;
import com.tygz.service.SmsSendService;

@Service
public class SmsSendServiceImpl implements SmsSendService {
	

	@Override
	public boolean send(String code,String mobiles) throws Exception {
//		String uri = "http://222.73.117.158/msg/";//应用地址
//		String account = "jiekou-clcs-03";//账号
//		String pswd = "Tch654321";//密码
//		String mobiles = "18674863295";//手机号码，多个号码使用","分割
//		String content = "亲爱的用户，您的验证码是123456，5分钟内有效。";//短信内容
//		boolean needstatus = true;//是否需要状态报告，需要true，不需要false
//		String product = null;//产品ID
//		String extno = null;//扩展码
		 String content = CommonConstants.SMS_MODEL;
		 content =  content.replace("${code}", code);
		try {
			String returnString = HttpSender.batchSend(CommonConstants.SMS_URL, CommonConstants.SMS_ACCOUNT, CommonConstants.SMS_PWD,
					mobiles, content, CommonConstants.SMS_NEEDSTATUS, CommonConstants.SMS_PRODUCT, CommonConstants.SMS_EXTNO);
			System.out.println("SMS-return:"+returnString);
			if(null == returnString){
				return false;
			}
			if(returnString.contains("\n")){
				String[] arr = returnString.split("\n"),arr1 = arr[0].split(",");
				if(arr1.length<2){
					return false;
				}
				if(arr1[1].equals("0")){
					return true;
				}
				return false;
				
			}
			return false;
			
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}

}
